package com.eonmind.ai.mapper;

import com.eonmind.common.contract.data.base.BaseMongoMapper;
import com.eonmind.common.contract.enums.DelEnum;
import com.eonmind.common.contract.enums.StatusEnum;
import com.eonmind.common.provider.entity.ai.AiAssistant;
import com.mongoplus.conditions.query.QueryWrapper;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AiAssistantMapper extends BaseMongoMapper<AiAssistant> {

    public AiAssistant selectById(Long assistantId) {
        QueryWrapper<AiAssistant> eq = createMgoQuery().eq(AiAssistant::getId, assistantId)
                .eq(AiAssistant::getStatus, StatusEnum.OPENED.getCode())
                .eq(AiAssistant::getDel, DelEnum.UN_DEL.getCode());

        return one(eq);
    }

    // TODO 模糊查询 待优化
    public List<AiAssistant> selectByName(String keyword) {
        QueryWrapper<AiAssistant> text = createMgoQuery()
                .or(t -> {
                    t.like(AiAssistant::getAssistantName, keyword)
                            .like(AiAssistant::getAssistantPrompt, keyword);
                    return t;
                });
        return list(text);
    }
}
